package viper.mysql;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;

/**
 * @author Kevin Sin
 * 11/17/09
 * This is a test for a user logging in and using MySQLFunctions to log in and
 * see who else is online.
 */
public class LoginTest {
	
	public static String name = "Testing";
	
	public static String getIP() {
		String ip_addr = null;
		try {
			InetAddress address = InetAddress.getLocalHost();
			ip_addr = address.getHostAddress();
		} catch (UnknownHostException e) {
			e.printStackTrace();
		}
		return ip_addr;
	}
	
	public static void displayUsers()
	{
		ArrayList<Object[]> userlist = MySQLFunctions.getCurrentUsers();
		for(Object[] row : userlist)
		{
			System.out.println(row[0] + "---" + row[1] + "---" + row[2]);
		}
	}
	
	public static void main(String[] args) {
		String ip_addr = getIP();
		if(ip_addr!=null)
		{
			MySQLFunctions.login(ip_addr, name);
			MySQLFunctions.updateStatus(ip_addr, MySQLFunctions.STATUS_BUSY);
		}
		displayUsers();
		MySQLFunctions.logout(ip_addr);
	}
}
